package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TourismActiviteSign;
import com.ruoyi.system.domain.TourismPact;
import com.ruoyi.system.domain.TourismUser;
import com.ruoyi.system.mapper.TourismActiviteSignMapper;
import com.ruoyi.system.mapper.TourismPactMapper;
import com.ruoyi.system.mapper.TourismUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TourismActivitiesMapper;
import com.ruoyi.system.domain.TourismActivities;
import com.ruoyi.system.service.ITourismActivitiesService;

import javax.annotation.Resource;

/**
 * 特色活动Service业务层处理
 *
 * @author gqd
 * @date 2020-12-29
 */
@Service
public class TourismActivitiesServiceImpl implements ITourismActivitiesService
{
    @Autowired
    private TourismActivitiesMapper tourismActivitiesMapper;
    @Resource
    private TourismPactMapper tourismPactMapper;
    @Resource
    private TourismUserMapper tourismUserMapper;
    @Resource
    private TourismActiviteSignMapper tourismActiviteSignMapper;

    /**
     * 查询特色活动
     *
     * @param id 特色活动ID
     * @return 特色活动
     */
    @Override
    public TourismActivities selectTourismActivitiesById(Long id)
    {
        return tourismActivitiesMapper.selectTourismActivitiesById(id);
    }

    /**
     * 查询特色活动列表
     *
     * @param tourismActivities 特色活动
     * @return 特色活动
     */
    @Override
    public List<TourismActivities> selectTourismActivitiesList(TourismActivities tourismActivities)
    {
        return tourismActivitiesMapper.selectTourismActivitiesList(tourismActivities);
    }

    /**
     * 新增特色活动
     *
     * @param tourismActivities 特色活动
     * @return 结果
     */
    @Override
    public int insertTourismActivities(TourismActivities tourismActivities)
    {
        tourismActivities.setCreateTime(DateUtils.getNowDate());
        return tourismActivitiesMapper.insertTourismActivities(tourismActivities);
    }

    /**
     * 修改特色活动
     *
     * @param tourismActivities 特色活动
     * @return 结果
     */
    @Override
    public int updateTourismActivities(TourismActivities tourismActivities)
    {
        return tourismActivitiesMapper.updateTourismActivities(tourismActivities);
    }

    /**
     * 批量删除特色活动
     *
     * @param ids 需要删除的特色活动ID
     * @return 结果
     */
    @Override
    public int deleteTourismActivitiesByIds(Long[] ids)
    {
        return tourismActivitiesMapper.deleteTourismActivitiesByIds(ids);
    }

    /**
     * 删除特色活动信息
     *
     * @param id 特色活动ID
     * @return 结果
     */
    @Override
    public int deleteTourismActivitiesById(Long id)
    {
        return tourismActivitiesMapper.deleteTourismActivitiesById(id);
    }


    @Override
    public AjaxResult selectActivities() {
        List<TourismActivities> tourismActivities = tourismActivitiesMapper.selectActivities();
        if(tourismActivities.size() == 0 || tourismActivities == null){
            return AjaxResult.error("暂时没有活动信息");
        }
        return AjaxResult.success(tourismActivities);
    }

    @Override
    public AjaxResult selectActivitiesById(Integer id,Integer userId) {
        TourismUser tourismUser = tourismUserMapper.selectByUserId(userId);

        TourismActivities tourismActivities = tourismActivitiesMapper.selectActivitiesById(id);
        if(tourismActivities == null){
            return AjaxResult.error("暂时还没有该活动的具体信息！");
        }
        if(tourismUser == null || userId == null){
            tourismActivities.setFlag("0");
            tourismActivities.setSignFlag("0");
        }else{
            TourismPact tourismPact = tourismPactMapper.selectSpotPact5(id,userId);
            if(tourismPact == null){
                tourismActivities.setFlag("0");
            }else {
                tourismActivities.setFlag("1");
            }
            TourismActiviteSign tourismActiviteSign = tourismActiviteSignMapper.selectByIdAndUserId(id, userId);
            if(tourismActiviteSign == null){
                tourismActivities.setSignFlag("0");
            }else {
                tourismActivities.setSignFlag("1");
            }

        }
        return AjaxResult.success(tourismActivities);
    }
}
